//
//  InfomationHeaderView.m
//  Rail
//
//  Created by hychen on 2018/2/27.
//  Copyright © 2018年 Hychen. All rights reserved.
//

#import "InfomationHeaderView.h"

@interface InfomationHeaderView ()
@property (weak, nonatomic) IBOutlet UIImageView *warnImage;
@property (weak, nonatomic) IBOutlet UILabel *currentWarnLabel;
@property (weak, nonatomic) IBOutlet UILabel *currentWarnDescLabel;
@property (weak, nonatomic) IBOutlet UILabel *todoWarnNumLabel;
@property (weak, nonatomic) IBOutlet UIView *todoWarnView;
@property (weak, nonatomic) IBOutlet UILabel *allWarnNumLabel;
@property (weak, nonatomic) IBOutlet UIView *allWarnView;
@property (weak, nonatomic) IBOutlet UILabel *noticeWarnNumLabel;
@property (weak, nonatomic) IBOutlet UIView *noticeWarnView;

@end

@implementation InfomationHeaderView

+ (instancetype)headerView
{
    return [[[NSBundle mainBundle] loadNibNamed:@"InfomationHeaderView" owner:self options:nil] lastObject];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    BMWeakSelf
    [self.todoWarnView addTapGestureWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        if (weakSelf.BlockClickTodoWarn) {
            weakSelf.BlockClickTodoWarn();
        }
    }];
    
    [self.allWarnView addTapGestureWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        if (weakSelf.BlockClickAllWarn) {
            weakSelf.BlockClickAllWarn();
        }
    }];
    
    [self.noticeWarnView addTapGestureWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        if (weakSelf.BlockClickNotice) {
            weakSelf.BlockClickNotice();
        }
    }];
    
}

- (void)setModel:(InformationAlertModel *)model {
    _model = model;
    
    //报警图片
    [self setHeadWarnStyle:[model.current_count integerValue] > 0];
    self.currentWarnLabel.text = model.current_count?:@"0";
    
    self.todoWarnNumLabel.text = model.processing_count;
    self.allWarnNumLabel.text = model.all_count;
    self.noticeWarnNumLabel.text = model.notice_count;
}

- (void)setHeadWarnStyle:(BOOL)isWarn {
    NSString *imageName = isWarn?@"information_warn_img":@"information_on_warn_img";
    self.warnImage.image = [UIImage imageNamed:imageName];
}

- (IBAction)settingButtonClick:(UIButton *)sender {
    if (self.BlockClickSetting) {
        self.BlockClickSetting();
    }
}

- (IBAction)currentWarnListClick:(UIButton *)sender {
    if (self.BlockClickCurrentWarn) {
        self.BlockClickCurrentWarn();
    }
}
@end
